﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using BTSDecompress.ClassLibrary;
namespace BTSDecompress_cmd
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length == 0 || args[0] == "-?")
            {
                ShowHelp();
                return;
            }

            Initialize(args);

        }
        static void Initialize(string[] args)
        {
            SqlQuery sqlQuery = new SqlQuery();

            // Parse parameters
            Utils.ParseParameters(args, sqlQuery);
            
            // Load File and Store Settings
            Utils.LoadFile(sqlQuery);

            // Parse and Run Query
            System.Data.DataTable dataTable = new System.Data.DataTable();
            string msg = Utils.ExecuteQuery(sqlQuery, out dataTable);

            // Output results
            if (sqlQuery.OverwriteOutputFile)
            {
                File.WriteAllText(sqlQuery.OutputFile, msg);
            }
            else
            {
                File.AppendAllText(sqlQuery.OutputFile, msg);
            }
        }
        static void ShowHelp()
        {
            Console.WriteLine(@"BTSDecompress_cmd -s:<Database Server>
                  -d:<Database>
                  -SQLFile:<SQL file>
                  -OutputFile:<Output File>
                  -OverwriteOutputFile
                  -Namespace:<prefix>:<namespace>
                  -HideOuterXMLTag
                  -HideContextPropertyNames
                  -ShowColumnNames
                  -UseFieldSeperator
                  -BlankLineBetweenRecords
                  -?"); 
        }
    }
}
